import tkinter as tk
from tkinter import messagebox
from datetime import datetime
import time



def enter():
    global entry_username
    global entry_password
    root = tk.Tk()
    root.title("登陆注册页面")
    root.geometry("300x200+700+300")

# 创建用户名和密码输入框
    label_username = tk.Label(root, text="用户名：")
    label_username.pack()
    entry_username = tk.Entry(root)
    entry_username.pack()

    label_password = tk.Label(root, text="密码：")
    label_password.pack()
    entry_password = tk.Entry(root, show="*")
    entry_password.pack()

# 创建登录和注册按钮
    button_enter = tk.Button(root, text="登录", command=login)
    button_enter.pack(pady=5)

    button_register = tk.Button(root, text="注册", command=register)
    button_register.pack(pady=5)

    root.mainloop()
def login():

    username = entry_username.get()
    password = entry_password.get()

    if username == "张" and password == "123":
        messagebox.showinfo("登录成功", "欢迎进入待办事项，" + username + "!")
    else:
        messagebox.showerror("登录失败", "用户名或密码错误！")


def register():
    username = entry_username.get()
    password = entry_password.get()

    if username and password:
        messagebox.showinfo("注册成功", "注册成功，用户名：" + username + "，密码：" + password)
    else:
        messagebox.showwarning("注册失败", "请输入用户名和密码！")

# 创建主窗口


enter()
tasks = []
def add_task():
    task = entry_task.get()
    if task:
        tasks.append(task)
        update_listbox()
        entry_task.delete(0, tk.END)
    else:
        messagebox.showwarning("警告", "请先输入任务内容！")
def delete_task():
    try:
        index = listbox_tasks.curselection()[0]
        del tasks[index]
        update_listbox()
    except IndexError:
        messagebox.showwarning("警告", "请先选择一个任务！")
def mark_as_done():
    try:
        index = listbox_tasks.curselection()[0]
        tasks[index] = tasks[index] + " (完成)"
        update_listbox()
    except IndexError:
        messagebox.showwarning("警告", "请先选择一个任务！")
def sort_by_priority():
    tasks.sort(key=lambda x: "紧急" in x, reverse=True)
    update_listbox()
def update_listbox():
    listbox_tasks.delete(0, tk.END)
    for task in tasks:
        listbox_tasks.insert(tk.END, task)

root2 = tk.Tk()
root2.title("待办事项列表")


entry_task = tk.Entry(root2, width=50)
entry_task.pack(pady=10)

button_add = tk.Button(root2, text="添加任务", command=add_task)
button_add.pack(pady=5)



listbox_tasks = tk.Listbox(root2, height=10, width=50)
listbox_tasks.pack(pady=10)

button_delete = tk.Button(root2, text="删除任务", command=delete_task)
button_delete.pack(pady=5)

button_done = tk.Button(root2, text="标记为完成", command=mark_as_done)
button_done.pack(pady=5)

button_sort = tk.Button(root2, text="按紧急程度排序", command=sort_by_priority)
button_sort.pack(pady=5)

def add_task():
    task = entry_task.get()
    if task:
        tasks.append(task)
        update_listbox()
        entry_task.delete(0, tk.END)
    else:
        messagebox.showwarning("警告", "请先输入任务内容！")
def delete_task():
    try:
        index = listbox_tasks.curselection()[0]
        del tasks[index]
        update_listbox()
    except IndexError:
        messagebox.showwarning("警告", "请先选择一个任务！")
def mark_as_done():
    try:
        index = listbox_tasks.curselection()[0]
        tasks[index] = tasks[index] + " (完成)"
        update_listbox()
    except IndexError:
        messagebox.showwarning("警告", "请先选择一个任务！")
def sort_by_priority():
    tasks.sort(key=lambda x: "紧急" in x, reverse=True)
    update_listbox()
def update_listbox():
    listbox_tasks.delete(0, tk.END)
    for task in tasks:
        listbox_tasks.insert(tk.END, task)
def show_about_info():
    messagebox.showinfo("关于", "这是一个简单的待办事项小程序。\n作者：Your Name")


# 函数：显示提醒窗口
def show_reminder():
    messagebox.showinfo("提醒", "这是一个提醒窗口。")

menu_bar = tk.Menu(root2)
root2.config(menu=menu_bar)
# 添加菜单栏中的选项
file_menu = tk.Menu(menu_bar, tearoff=0)
menu_bar.add_cascade(label="文件", menu=file_menu)
file_menu.add_command(label="退出", command=root2.quit)

help_menu = tk.Menu(menu_bar, tearoff=0)
menu_bar.add_cascade(label="帮助", menu=help_menu)
help_menu.add_command(label="关于", command=show_about_info)

remind_menu = tk.Menu(menu_bar, tearoff=0)
menu_bar.add_cascade(label="提醒", menu=file_menu)
remind_menu.add_command(label="提醒", command=show_reminder)
root2.mainloop()